﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WBControl.aspx.cs" Inherits="Web.Admin.WebSiteSetting.WBControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
      <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <link href="../../Styles/Common.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/Common.js" type="text/javascript"></script>
    <script src="../../Scripts/WebInner.js" type="text/javascript"></script>
    <script src="../../Scripts/Zebra/zebra_dialog.js" type="text/javascript"></script>
    <link href="../../Scripts/Zebra/zebra_dialog.css" rel="stylesheet" type="text/css" />
    <style type="text/css">

</style>
<script type="text/javascript">
    function change_colorOver(e) {
        var oldColor = e.style.backgroundColor;
        document.getElementById("colorName").value = oldColor;
        e.style.backgroundColor = "#b9bace";
    }
    function change_colorOut(e) {
        e.style.backgroundColor = document.getElementById("colorName").value;
    }
    function HelpOpen() {
        $('#divHelp').fadeIn();
    }

    function HelpClose() {
        $('#divHelp').fadeOut();
    }

    $(function () {
        //显示网点类型
        $.ajax({
            url: 'ws.ashx?type=getWBType',
            type: 'post',
            data: '',
            dataType: 'json',
            success: function (r) {
                for (var i = 0; i < r.length; i++) {
                    $('select[name=WBType_ID]').append("<option value='" + r[i].ID + "'>" + r[i].strType + "</option>");
                }
            }, error: function (r) {
                $.Zebra_Dialog('<strong>加载网点类型失败 ！</strong>');
            }
        });

    });

    function ShowFrm(wbid) {
        $('#divfrm').fadeIn("normal");
        $('#WBID').val(wbid);
        if (wbid == "0") {//新建网点
            $('#trAdd').fadeIn("fast");
            $('#trUpdate').fadeOut("fast");
            $('input[name=sNumber]').val('000');
            $('input[name=strType]').val('');
            $('input[name=strAddress]').val('');
            $('input[name=numAgent]').val('0');
            $('input[name=numSettle]').val('0');
            $('input[name=numDay]').val('180');

        }
        else { //编辑网点
            $('#trAdd').fadeOut("fast");
            $('#trUpdate').fadeIn("fast");

            /*--------数据提交--------*/
            $.ajax({
                url: 'ws.ashx?type=GetWBByID&ID=' + wbid,
                type: 'post',
                data: '',
                dataType: 'json',
                success: function (r) {
                    $('input[name=sNumber]').val(r[0].SerialNumber);
                    $('input[name=strType]').val(r[0].strName);
                    $('input[name=strAddress]').val(r[0].strAddress);
                    $('input[name=numAgent]').val(r[0].numAgent);
                    $('input[name=numSettle]').val(r[0].numSettle);
                    $('input[name=numDay]').val(r[0].numDay);
                    $("select[name=WBType_ID]  option[value='" + r[0].WBType_ID + "'] ").attr("selected", "selected")
                    if (r[0].ISAllowBackUp == true) {
                        $('input[name=ISAllowBackUp]').attr("checked", "checked");
                    } else {
                        $('input[name=ISAllowBackUp]').removeAttr("checked");
                    }

                }, error: function (r) {
                    $.Zebra_Dialog('<strong>加载网点数据失败 ！</strong>');
                }
            });
            /*--------End 数据提交--------*/
        }

    }
    function CloseFrm() {
        $('#divfrm').fadeOut("normal");
    }

    //添加、修改网点 （ID=0是添加网点）
    function WBUpdate() {
        if (!SubmitCheck()) {//检测输入内容
            return false;
        }
     

        var wbid = $('#WBID').val();
        if (confirm("您确认已经仔细检查输入信息，并继续操作吗？")) {
            /*--------数据提交--------*/
            $.ajax({
                url: 'ws.ashx?type=UpdateWB&ID=' + wbid + "&sNumber=" + $('input[name=sNumber]').val(),
                type: 'post',
                data: $('#form1').serialize(),
                dataType: 'txt',
                success: function (r) {
                    if (r == "OK") {
                        if (wbid == "0") {
                            $.Zebra_Dialog('<strong>添加数据成功 ！</strong>');
                        } else {
                            $.Zebra_Dialog('<strong>更新数据成功 ！</strong>');
                        }
                        CloseFrm();
                        location.reload();
                    } else if (r == "1") {
                        $.Zebra_Dialog('<strong>已存在相同的网点名称，请修改后添加 ！</strong>');
                    }
                }, error: function (r) {
                    $.Zebra_Dialog('<strong>加载网点类型失败 ！</strong>');
                }
            });
            /*--------End 数据提交--------*/

        }
    }

    //提交检测
    function SubmitCheck() {
        var wbid = $('#WBID').val();



        if ($('input[name=strType]').val() == "") {
            $.Zebra_Dialog('<strong>请输入网点名称 ！</strong>');
            $('input[name=strType]').focus();
            return false;
        }
        if ($('input[name=strAddress]').val() == "") {
            $.Zebra_Dialog('<strong>请输入网点地址 ！</strong>');
            $('input[name=strAddress]').focus();
            return false;
        }

        if (isNaN($('input[name=numSettle]').val())) {
            $.Zebra_Dialog('<strong>结算扣率请输入数字 ！</strong>');
            $('input[name=numSettle]').focus();
            return false;
        }
        if (isNaN($('input[name=numAgent]').val())) {
            $.Zebra_Dialog('<strong>代理费率请输入数字 ！</strong>');
            $('input[name=numAgent]').focus();
            return false;
        }
        return true;

    }


    function WBDelete() {
        var wbid = $('#WBID').val();
        if (confirm("您确认要删除此网点吗？")) {
            /*--------数据提交--------*/
            $.ajax({
                url: 'ws.ashx?type=DeleteWBByID&ID=' + wbid,
                type: 'post',
                data: '',
                dataType: 'txt',
                success: function (r) {
                    if (r == "OK") {
                        $.Zebra_Dialog('<strong>删除数据成功！</strong>');
                        CloseFrm();
                        location.reload();
                    } else {
                        $.Zebra_Dialog('<strong>删除数据失败 ！</strong>');
                    }
                }, error: function (r) {
                    $.Zebra_Dialog('<strong>删除数据失败 ！</strong>');
                }
            });
            /*--------End 数据提交--------*/

        }
    }

   
     
</script>
</head>
<body>
   <form id="form1" runat="server">
 <div class="pageHead">
        <b>网点设置</b><span id="spanHelp" style="cursor: pointer">帮助</span>
    </div>
    <div id="divHelp" class="pageHelp">
        <span>提示1：总部用于管理其它网点，每个单位可以设置一个总部；如果想把某个网点设为总部，在设置网点中单击“设为总部”；每个单位可以设置一个模拟网点用于练习，单击指定模拟网点即可设置。</span>
        <br />
        <span>提示2：单击“查看/修改”时可以修改所选网点的详细信息。</span><br />
    </div>

<div class="QueryHead">
<table>
            <tr>
            <td><span>按网点名称查询:</span></td>
            <td><span><input type="text" id="txtType" runat="server" /> </span></td>
            <td style="width:60px">
                <asp:ImageButton ID="ImageButton1" runat="server" 
                    ImageUrl="~/images/seach_brown.png" onclick="ImageButton1_Click" />
                </td>
            <td><%=GetAddItem() %></td>
            </tr>
            
        </table>
</div>
<asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
        <table  class="tabData" style="width:900px">
          <tr class="tr_head" >
                <th style="width:100px; text-align:center;">
                    网点编号</th>
                <th style="width:100px; text-align:center;">
                    网点名称</th>
                <th style="width:200px; text-align:center;">
                    网点地址</th>
                <th style="width:100px; text-align:center;">
                    网点类型</th>
                    <th style="width:100px; text-align:center;">
                    代理费率</th>
                    <th style="width:100px; text-align:center;">
                    允许备份</th>
                    <th style="width:120px; text-align:center;">
                    查看/修改</th>
            </tr>
        
    </HeaderTemplate>
    <ItemTemplate>
    <tr style='background-color: <%#(Container.ItemIndex%2==0)?"#FFFFF;":"#fcf3f4"%>' onmouseover="change_colorOver(this)" onmouseout="change_colorOut(this)">
        <td><%#Eval("SerialNumber")%></td>
        <td><%#Eval("strName")%><%#SetISHQ(Eval("ISHQ"),Eval("ISSimulate")) %></td>
        <td><%#Eval("strAddress")%></td>
        <td><%#Eval("WBType_ID")%></td>
        <td><%#Eval("numAgent")%></td>
        <td><%#SetISAllowBackUp(Eval("ISAllowBackUp"))%></td>
        <td><%#GetUpdateItem(Eval("ID")) %></td>
 
    </tr>
    </ItemTemplate>
    
    <FooterTemplate><!--底部模板-->
        </table>        <!--表格结束部分-->
        </FooterTemplate>
    </asp:Repeater>
   
    <div  id="divfrm" class="pageEidt" style="display:none; width:400px; height:340px;">
    <div style="float:right; margin:10px 20px">
    <img src="../../images/winClose.png" alt="关闭窗口"  style="float:right; cursor:pointer;" onclick="CloseFrm()" />
   <%-- <input type="button" style="width:60px; background-color:#ccc;" value="关闭" onclick="CloseFrm()" /></div>--%>    
    <br />
    <div style="clear:both">
        <table >
            <tr>
            <td style="width:120px"><span>网点序号:</span></td>
            <td><input type="text" name="sNumber" disabled="disabled" style=" font-Size:18px; font-Weight:Bold; " /></td>
            </tr>
            <tr>
            <td><span>网点类型:</span></td>
            <td><select name="WBType_ID" style="width:100px; height:25px"></select></td>
            </tr>
             <tr>
            <td><span>网点名称:</span></td>
            <td><input type="text" name="strType" /></td>
            </tr>
             <tr>
            <td><span>网点地址:</span></td>
            <td><input type="text" name="strAddress" /></td>
            </tr>
             <tr>
            <td><span>结算扣率:</span></td>
            <td><input type="text" name="numSettle" /></td>
            </tr>
             <tr>
            <td><span>代理费率:</span></td>
            <td><span><input type="text" name="numAgent" /> </span></td>
            </tr><tr>
            <td><span>最低保管期限:</span></td>
            <td><span><input type="text" name="numDay" /> </span></td>
            </tr>
             <tr>
            <td><span>备份权限:</span></td>
            <td><input type="checkbox" name="ISAllowBackUp" /> <span>允许网点随时备份数据</span></td>
            </tr>
            <tr id="trAdd">
            <td></td>
            <td ><input type="button" id="btnAdd" value="添加网点" onclick="WBUpdate()" /> </td>
            </tr>
               <tr id="trUpdate">
            <td></td>
            <td ><input type="button" id="btnUpdate" value="修改网点" onclick="WBUpdate()" />
            <input type="button" id="btnDel" value="删除网点" style="display:none;" onclick="WBDelete()" />
              
             </td>
            </tr>
        </table>
        </div>
    </div>

    </form>
    <%--定义编号--%>
    <input type="hidden" id="WBID" value="" />
    <%--定义背景色的隐藏域--%>
    <input type="hidden" id="colorName" value="" />
</body>
</html>
